| Conditions | 3 |
| Paths | 3 |
| Total Lines | 66 |
| Code Lines | 43 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | const Response = require('../util/response') |
||
| 9 | test: async function (ctx) { |
||
| 10 | |||
| 11 | console.log('controller input') |
||
|
|
|||
| 12 | console.log(ctx.input) |
||
| 13 | console.log(ctx.params) |
||
| 14 | |||
| 15 | let conflict = [] |
||
| 16 | let tmpNo = 'none' |
||
| 17 | let orderNo = [] |
||
| 18 | for (let index = 0; index < 100; index++) { |
||
| 19 | let genNo = await Uuid.genOrderNo() |
||
| 20 | orderNo[index] = genNo |
||
| 21 | if (genNo === tmpNo) { |
||
| 22 | conflict.push(genNo) |
||
| 23 | } |
||
| 24 | tmpNo = genNo |
||
| 25 | } |
||
| 26 | orderNo.reverse() |
||
| 27 | |||
| 28 | let orderResult = { |
||
| 29 | "conflict": conflict, |
||
| 30 | "order": orderNo |
||
| 31 | } |
||
| 32 | |||
| 33 | let rules = { |
||
| 34 | 'uid': 'numeric|in:"0","3","4"', |
||
| 35 | 'filter': 'in:1,2,3', |
||
| 36 | } |
||
| 37 | |||
| 38 | let message = { |
||
| 39 | 'uid.required': 'kkkk', |
||
| 40 | 'uid.numeric': '数字数字', |
||
| 41 | 'uid.in': 'uid 必须在xxx范围内' |
||
| 42 | } |
||
| 43 | |||
| 44 | Validate(ctx, rules, message) |
||
| 45 | |||
| 46 | Redis.set('testkey', JSON.stringify(message)) |
||
| 47 | Redis.expire('testkey', 86400 * 30) |
||
| 48 | |||
| 49 | let insertData = [ |
||
| 50 | { |
||
| 51 | 'name': 'te', |
||
| 52 | 'user_id': 1, |
||
| 53 | 'description': 'uni * 2' |
||
| 54 | }, |
||
| 55 | { |
||
| 56 | 'name': 'test2', |
||
| 57 | 'user_id': 2, |
||
| 58 | 'description': 'test2' |
||
| 59 | }, |
||
| 60 | ] |
||
| 61 | |||
| 62 | let sigleData = { |
||
| 63 | 'name': '测试', |
||
| 64 | 'user_id': 2, |
||
| 65 | 'description': 'test4' |
||
| 66 | } |
||
| 67 | |||
| 68 | let realInsertData = { |
||
| 69 | 'openid': 'test' + new Date().getTime() |
||
| 70 | } |
||
| 71 | // insertData = await ModelUser.addUser(realInsertData) |
||
| 72 | |||
| 73 | return Response.output(ctx, orderResult) |
||
| 74 | }, |
||
| 75 | |||
| 97 | } |